<template>
  <div class="sidebar tanxin">
    <!-- 登录状态 -->
    <div class="load" v-if="$store.state.isLogin">
      <div class="face">
        <img :src="profile.avatarUrl" alt=""  @click="$router.push(`/user/${uid}`)" />
        <div class="info">
          <h4  @click="$router.push(`/user/${uid}`)">{{ profile.nickname }}</h4>
          <span>Lv.{{ userData.level }}</span>
          <a class="sign" href="javascript:;" target="_blank">
            签到<a class="sign_r"></a>
          </a>
        </div>
      </div>
      <ul class="day">
        <li>
          <strong>{{ profile.eventCount }}</strong>
          <span>动态</span>
        </li>
        <li>
          <strong>{{ profile.follows }}</strong>
          <span>关注</span>
        </li>
        <li>
          <strong>{{ profile.followeds }}</strong>
          <span>粉丝</span>
        </li>
      </ul>
    </div>

    <!-- 未登录状态 -->
    <div class="unload" v-else>
      <p class="note">
        登录云音乐，可以享受无限收藏的乐趣，并且无限同步到手机。
      </p>
      <div class="btn" @click="goLogin">
        用户登录<a class="btn_r"></a>
      </div>
    </div>
  </div>
</template>

<script>
import { UserDetailApi } from "@/request/api";
export default {
  data() {
    return {
      // 用户id
      uid: 2081534865,
      userData: "",
      profile: "",
      // 是否登录，默认false未登录
      isLogin: false,
    };
  },
  created() {
    UserDetailApi(this.uid).then((res) => {
      // console.log(res);
      this.userData = res.data;
      this.profile = res.data.profile;
    })
  },
  methods: {
    goLogin() {
      let token = localStorage.getItem("user");
      if (token) {
        setTimeout(() => {
          this.$store.commit("isHeaderShow", true);
          this.$store.commit("isLoginShow", true);
          this.$router.push("/mymusic");
        }, 2000)
        // 提示成功
        let obj = { content: "登录成功", icon: "success" };
        this.$store.dispatch("AsyncToast", obj);
      } else {
        // 需要改变登录那个框的v-show的状态
        this.$store.commit("changeLoginShow", true);
        // 提示登录
        let obj = { content: "请先登录", icon: "info" };
        this.$store.dispatch("AsyncToast", obj);
      }
    },
  },
};
</script>
 
<style lang = "less" scoped>
@import "../../assets/base.less";
.load {
  width: 100%;
  height: 160px;
  padding-top: 20px;
  background: linear-gradient(to bottom, #fff, #f5f5f5);
  .face {
    height: 90px;
    display: flex;
    img {
      cursor: pointer;
      margin-left: 20px;
      height: 80px;
    }
    .info {
      margin-left: 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      h4 {
        font-size: 14px;
        color: #333;
        font-weight: bold;
        &:hover {
          cursor: pointer;
          text-decoration: underline;
        }
      }
      span {
        display: block;
        font-size: 12px;
        font-weight: bold;
        color: #999999;
        border: 1px solid #999999;
        border-radius: 10px;
        height: 16px;
        width: 20px;
        line-height: 16px;
        text-align: center;
        padding: 0 10px;
        &:hover {
          cursor: pointer;
          color: #666;
          border: 1px solid #666;
        }
      }
      .sign {
        position: relative;
        width: 100px;
        height: 31px;
        background: url("@/assets/images/public/button2.png") no-repeat;
        background-position: 0 -387px;
        font-size: 12px;
        color: #fff;
        line-height: 31px;
        text-align: center;
        vertical-align: top;
        border-radius: 3px;
        .sign_r {
          position: absolute;
          right: 0;
          width: 6px;
          height: 31px;
          display: inline-block;
          background: url("@/assets/images/public/button2.png") no-repeat;
          background-position: -244px -428px;
        }
        &:hover {
          cursor: pointer;
          background-position: 0 -469px;
          .sign_r {
            background-position: -244px -510px;
          }
        }
      }
    }
  }
  .day {
    width: 250px;
    height: 40px;
    margin-top: 20px;
    display: flex;
    justify-content: space-around;
    li {
      cursor: pointer;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      padding: 20px;
      border-right: 2px solid #ccc;
      &:last-of-type {
        border: none;
      }
      strong {
        font-size: 20px;
        color: #666;
      }
      span {
        font-size: 12px;
        color: #666;
        margin-top: 5px;
      }
      &:hover strong,
      &:hover span {
        background: @red;
      }
    }
  }
}
.unload {
  width: 100%;
  height: 126px;
  background: linear-gradient(to bottom, #fff, #d3d3d3);
  .note {
    width: 200px;
    font-size: 12px;
    color: #666666;
    margin: 0 auto;
    padding: 16px 0;
    line-height: 22px;
  }
  .btn {
    position: relative;
    margin: 0 auto;
    width: 100px;
    height: 31px;
    background: url("@/assets/images/public/button2.png") no-repeat;
    background-position: 0 -387px;
    font-size: 12px;
    color: #fff;
    line-height: 31px;
    text-align: center;
    vertical-align: top;
    border-radius: 3px;
    .btn_r {
      position: absolute;
      right: 0;
      width: 6px;
      height: 31px;
      display: inline-block;
      background: url("@/assets/images/public/button2.png") no-repeat;
      background-position: -244px -428px;
    }
    &:hover {
      cursor: pointer;
      background-position: 0 -469px;
      .btn_r {
        background-position: -244px -510px;
      }
    }
  }
}
</style>